#pragma once
#include "IUIDialog.h"
#include "DrawUITree.h"
namespace UILib
{
    const wchar_t wszUIWndName[] = L"UILib_Dialog";
    class CDrawDialog : public CWindowImpl<CDrawDialog, CWindow>\
        , public IUIDialog\
        , public RanderObserver
    {
    public:
        CDrawDialog(const UINT uID = -1);
        virtual ~CDrawDialog(void);

        DECLARE_WND_CLASS(wszUIWndName)
        virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID = 0);

    public:
        virtual void InitParam(const PDialogParam pParam);

        virtual void Show( const UINT uWSP, const bool bCenter = false );

        virtual HWND Get_HWnd() const{ return m_hWnd; };

        virtual void Set_DialogEvent( const PDialogEvent pEvent );

        virtual void Set_CustomObserver(const PCustomObserver pObserver );

        virtual void Add_MessageFilter( const PUIMessageFilter pFilter );

        virtual void BindUITree( CDrawUITree* pUITree );
        virtual CDrawUITree* GetUITree() const { return DrawUITree_; };

        virtual void Set_ID( const UINT uID );
        virtual UINT Get_ID() const { return uID_; };

        virtual void Set_BackgroundColor( const COLORREF cl );

        virtual void Set_LayoutAttr(const bool bLayout = false);

        virtual void Set_Caption( const RECT rcCaption );

        virtual  CDrawView* GetChildrenByID(const UINT uID);

        virtual void OnLayoutCheck();
    protected:
        virtual LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnNcDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnLbuttonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnLbuttonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
        virtual LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

        virtual void Render(const PAINTSTRUCT &ps);

        CDrawView* GetElement(const UINT uID);

        void UpdateWindow();
        static  HBITMAP CreateMyBitmap(HDC hDC, int cx, int cy, COLORREF** pBits);
    protected:
        UINT                uID_;
        PDialogEvent        DialogEvent_;
        PCustomObserver     CustomObserver_;
        PUIMessageFilter    MsgFilter_;

        CDrawUITree*        DrawUITree_;

        HWND                hOwner_;
        bool                bInit_;
        bool                bChild_;
        bool                bLostFocusClose;
        bool                bTracking_;
        bool                bLayout_;

        RECT                rcCaption_;

        COLORREF            clBackGround_;

        bool                bNeedLayout_;

        SIZE                szOld;
    };
}
